﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
    public class DAO_QLPhanCongDT
    {
        public static List<DTO_QLPhanCongDT> QlPhanCongDt_TheoMaKH_MaloaiDt(string makhoahoc, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "Prc_QLPCDT";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar).Value = makhoahoc;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();
                    PCDT.ID_PCDT = int.Parse(dt.Rows[i]["ID_PCDT"].ToString());
                    PCDT.MaDT = dt.Rows[i]["MaDT"].ToString();
                    PCDT.MaSV = dt.Rows[i]["MaSV"].ToString();
                    PCDT.MaCN = dt.Rows[i]["MaCN"].ToString();
                    PCDT.MaKH = dt.Rows[i]["MaKH"].ToString();
                    PCDT.MaLoaiDT = dt.Rows[i]["MaLoaiDT"].ToString();
                    PCDT.NgayNhan = DateTime.Parse(dt.Rows[i]["NgayNhan"].ToString());
                    PCDT.NgayHetHan_ChonDT = DateTime.Parse(dt.Rows[i]["NgayHetHan_ChonDT"].ToString());
                    PCDT.DiemNHD = float.Parse(dt.Rows[i]["DiemNHD"].ToString());
                    PCDT.DiemPB = float.Parse(dt.Rows[i]["DiemPB"].ToString());
                    listPCDT.Add(PCDT);
                }
                ketnoi.Cmb().Close();
                return listPCDT;
            }
            catch (Exception ex)
            {
                return listPCDT;
            }
        }
        public static List<DTO_QLPhanCongDT> SelectPhanCongDT()
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "Proc_SelectPhanCongDT";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();
                    PCDT.ID_PCDT = int.Parse(dt.Rows[i]["ID_PCDT"].ToString());
                    PCDT.MaDT = dt.Rows[i]["MaDT"].ToString();
                    PCDT.MaSV = dt.Rows[i]["MaSV"].ToString();
                    PCDT.MaCN = dt.Rows[i]["MaCN"].ToString();
                    PCDT.MaKH = dt.Rows[i]["MaKH"].ToString();
                    PCDT.MaLoaiDT = dt.Rows[i]["MaLoaiDT"].ToString();
                    PCDT.NgayNhan = DateTime.Parse(dt.Rows[i]["NgayNhan"].ToString());
                    PCDT.NgayHetHan_ChonDT = DateTime.Parse(dt.Rows[i]["NgayHetHan_ChonDT"].ToString());
                    PCDT.DiemNHD = float.Parse(dt.Rows[i]["DiemNHD"].ToString());
                    PCDT.DiemPB = float.Parse(dt.Rows[i]["DiemPB"].ToString());
                    listPCDT.Add(PCDT);
                }
                ketnoi.Cmb().Close();
                return listPCDT;
            }
            catch (Exception ex)
            {
                return listPCDT;
            }
        }
        public static List<DTO_QLPhanCongDT> Select_DaDKDT(string makhoahoc, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "Proc_DaDKDT";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar).Value = makhoahoc;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();
                    PCDT.ID_PCDT = int.Parse(dt.Rows[i]["ID_PCDT"].ToString());
                    PCDT.MaDT = dt.Rows[i]["MaDT"].ToString();
                    PCDT.MaSV = dt.Rows[i]["MaSV"].ToString();
                    PCDT.MaCN = dt.Rows[i]["MaCN"].ToString();
                    PCDT.MaKH = dt.Rows[i]["MaKH"].ToString();
                    PCDT.MaLoaiDT = dt.Rows[i]["MaLoaiDT"].ToString();
                    PCDT.NgayNhan = DateTime.Parse(dt.Rows[i]["NgayNhan"].ToString());
                    PCDT.NgayHetHan_ChonDT = DateTime.Parse(dt.Rows[i]["NgayHetHan_ChonDT"].ToString());
               
                    PCDT.DiemNHD = float.Parse(dt.Rows[i]["DiemNHD"].ToString());
                    PCDT.DiemPB = float.Parse(dt.Rows[i]["DiemPB"].ToString());
                    listPCDT.Add(PCDT);
                }
                ketnoi.Cmb().Close();
                return listPCDT;
            }
            catch (Exception ex)
            {
                return listPCDT;
            }
        }
        public static List<DTO_QLPhanCongDT> Select_ChuaDKDT(string makhoahoc, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "Proc_ChuaDKDT";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar).Value = makhoahoc;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();
                    PCDT.ID_PCDT = int.Parse(dt.Rows[i]["ID_PCDT"].ToString());
                    PCDT.MaDT = dt.Rows[i]["MaDT"].ToString();
                    PCDT.MaSV = dt.Rows[i]["MaSV"].ToString();
                    PCDT.MaCN = dt.Rows[i]["MaCN"].ToString();
                    PCDT.MaKH = dt.Rows[i]["MaKH"].ToString();
                    PCDT.MaLoaiDT = dt.Rows[i]["MaLoaiDT"].ToString();
                    PCDT.NgayNhan = DateTime.Parse(dt.Rows[i]["NgayNhan"].ToString());
                    PCDT.NgayHetHan_ChonDT = DateTime.Parse(dt.Rows[i]["NgayHetHan_ChonDT"].ToString());
                
                    PCDT.DiemNHD = float.Parse(dt.Rows[i]["DiemNHD"].ToString());
                    PCDT.DiemPB = float.Parse(dt.Rows[i]["DiemPB"].ToString());
                    listPCDT.Add(PCDT);
                }
                ketnoi.Cmb().Close();
                return listPCDT;
            }
            catch (Exception ex)
            {
                return listPCDT;
            }
        }
        public static List<DTO_QLPhanCongDT> Select_DTDangThucHien(string makhoahoc, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "Prc_DTDangTH";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar).Value = makhoahoc;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();
                    PCDT.ID_PCDT = int.Parse(dt.Rows[i]["ID_PCDT"].ToString());
                    PCDT.MaDT = dt.Rows[i]["MaDT"].ToString();
                    PCDT.MaSV = dt.Rows[i]["MaSV"].ToString();
                    PCDT.MaCN = dt.Rows[i]["MaCN"].ToString();
                    PCDT.MaKH = dt.Rows[i]["MaKH"].ToString();
                    PCDT.MaLoaiDT = dt.Rows[i]["MaLoaiDT"].ToString();
                    PCDT.NgayNhan = DateTime.Parse(dt.Rows[i]["NgayNhan"].ToString());
                    PCDT.NgayHetHan_ChonDT = DateTime.Parse(dt.Rows[i]["NgayHetHan_ChonDT"].ToString());
                 
                    PCDT.DiemNHD = float.Parse(dt.Rows[i]["DiemNHD"].ToString());
                    PCDT.DiemPB = float.Parse(dt.Rows[i]["DiemPB"].ToString());
                    listPCDT.Add(PCDT);
                }
                ketnoi.Cmb().Close();
                return listPCDT;
            }
            catch (Exception ex)
            {
                return listPCDT;
            }
        }
        public static List<DTO_QLPhanCongDT> Select_DTThucHienXong(string makhoahoc, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "Prc_DTTHXong";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar).Value = makhoahoc;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();
                    PCDT.ID_PCDT = int.Parse(dt.Rows[i]["ID_PCDT"].ToString());
                    PCDT.MaDT = dt.Rows[i]["MaDT"].ToString();
                    PCDT.MaSV = dt.Rows[i]["MaSV"].ToString();
                    PCDT.MaCN = dt.Rows[i]["MaCN"].ToString();
                    PCDT.MaKH = dt.Rows[i]["MaKH"].ToString();
                    PCDT.MaLoaiDT = dt.Rows[i]["MaLoaiDT"].ToString();
                    PCDT.NgayNhan = DateTime.Parse(dt.Rows[i]["NgayNhan"].ToString());
                    PCDT.NgayHetHan_ChonDT = DateTime.Parse(dt.Rows[i]["NgayHetHan_ChonDT"].ToString());
                 
                    PCDT.DiemNHD = float.Parse(dt.Rows[i]["DiemNHD"].ToString());
                    PCDT.DiemPB = float.Parse(dt.Rows[i]["DiemPB"].ToString());
                    listPCDT.Add(PCDT);
                }
                ketnoi.Cmb().Close();
                return listPCDT;
            }
            catch (Exception ex)
            {
                return listPCDT;
            }
        }
        public static bool insertQLPhanCongDT(DTO_QLPhanCongDT PCDT)
        {
            try
            {
                SqlConnection cn = ketnoi.Cmb();
                string s = "Proc_InsertPCDT";
                SqlCommand cmd1 = new SqlCommand(s, cn);
                cmd1.CommandType = CommandType.StoredProcedure;

                cmd1.Parameters.AddWithValue("@MaDT", PCDT.MaDT);
                cmd1.Parameters.AddWithValue("@MaSV", PCDT.MaSV);
                cmd1.Parameters.AddWithValue("@MaCN", PCDT.MaCN);
                cmd1.Parameters.AddWithValue("@MaKH", PCDT.MaKH);
                cmd1.Parameters.AddWithValue("@MaLoaiDT", PCDT.MaLoaiDT);
                cmd1.Parameters.AddWithValue("@NgayNhan", PCDT.NgayNhan);
                cmd1.Parameters.AddWithValue("@NgayHetHan_ChonDT", PCDT.NgayHetHan_ChonDT);
           
                cmd1.Parameters.AddWithValue("@DiemNHD", PCDT.DiemNHD);
                cmd1.Parameters.AddWithValue("@DiemPB", PCDT.DiemPB);

                if (cn.State == ConnectionState.Closed)
                    cn.Open();
                cmd1.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        public static bool UpdatePCDT(DTO_QLPhanCongDT PCDT, string ID_PCDT)
        {
            try
            {
                SqlConnection cn = ketnoi.Cmb();
                string s = "Proc_UpdatePCDT";
                SqlCommand cmd1 = new SqlCommand(s, cn);
                cmd1.CommandType = CommandType.StoredProcedure;
                // cmd1.Parameters.AddWithValue("@ID_PCDT", PCDT.ID_PCDT);
                cmd1.Parameters.AddWithValue("@MaDT", PCDT.MaDT);
                cmd1.Parameters.AddWithValue("@MaSV", PCDT.MaSV);
                cmd1.Parameters.AddWithValue("@MaCN", PCDT.MaCN);
                cmd1.Parameters.AddWithValue("@MaKH", PCDT.MaKH);
                cmd1.Parameters.AddWithValue("@MaLoaiDT", PCDT.MaLoaiDT);
                cmd1.Parameters.AddWithValue("@NgayNhan", PCDT.NgayNhan);
                cmd1.Parameters.AddWithValue("@NgayHetHan_ChonDT", PCDT.NgayHetHan_ChonDT);
          
                cmd1.Parameters.AddWithValue("@DiemNHD", PCDT.DiemNHD);
                cmd1.Parameters.AddWithValue("@DiemPB", PCDT.DiemPB);
                cmd1.Parameters.AddWithValue("@ID_PCDT", ID_PCDT);

                if (cn.State == ConnectionState.Closed)
                    cn.Open();
                cmd1.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        public static bool deleteQLPCDT(string ID_PCDT)
        {
            try
            {
                SqlConnection cn = ketnoi.Cmb();
                string s = "Proc_deleteQLPCDT";
                SqlCommand cmd1 = new SqlCommand(s, cn);
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.Parameters.AddWithValue("@ID_PCDT", ID_PCDT);
                if (cn.State == ConnectionState.Closed)
                    cn.Open();
                cmd1.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        public static List<DTO_QLPhanCongDT> SelectPhanCongDT_TheoKhoaHoc(string makhoahoc, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "Proc_SelectPhanCongDT_TheoKhoaHoc";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.AddWithValue("@MaKH", makhoahoc);
                cmd.Parameters.AddWithValue("@MaLoaiDT", maloaidt);
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();
                    PCDT.ID_PCDT = int.Parse(dt.Rows[i]["ID_PCDT"].ToString());
                    PCDT.MaDT = dt.Rows[i]["MaDT"].ToString();
                    PCDT.MaSV = dt.Rows[i]["MaSV"].ToString();
                    PCDT.MaCN = dt.Rows[i]["MaCN"].ToString();
                    PCDT.MaKH = dt.Rows[i]["MaKH"].ToString();
                    PCDT.MaLoaiDT = dt.Rows[i]["MaLoaiDT"].ToString();
                    PCDT.NgayNhan = DateTime.Parse(dt.Rows[i]["NgayNhan"].ToString());
                    PCDT.NgayHetHan_ChonDT = DateTime.Parse(dt.Rows[i]["NgayHetHan_ChonDT"].ToString());
                
                    PCDT.DiemNHD = float.Parse(dt.Rows[i]["DiemNHD"].ToString());
                    PCDT.DiemPB = float.Parse(dt.Rows[i]["DiemPB"].ToString());
                    listPCDT.Add(PCDT);
                }
                ketnoi.Cmb().Close();
                return listPCDT;
            }
            catch (Exception ex)
            {
                return listPCDT;
            }
        }
        public static bool UpdateDiem(float DiemNHD, float DiemPB, string ID_PCDT)
        {
            try
            {
                SqlConnection cn = ketnoi.Cmb();
                string s = "Prc_UpdateDiem";
                SqlCommand cmd1 = new SqlCommand(s, cn);
                cmd1.CommandType = CommandType.StoredProcedure;

                cmd1.Parameters.AddWithValue("@diem1", DiemNHD);
                cmd1.Parameters.AddWithValue("@diem2", DiemPB);
                cmd1.Parameters.AddWithValue("@id", ID_PCDT);

                if (cn.State == ConnectionState.Closed)
                    cn.Open();
                cmd1.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
        /* public static List<DTO_QLPhanCongDT> QlPhanCongDt_TheoMaKH_MaloaiDt(string makhoahoc, string maloaidt)
         {
             List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
             try
             {
                 string s = "Prc_QLPCDT";
                 SqlCommand cmd = new SqlCommand();
                 cmd.Connection = ketnoi.Cmb();
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.CommandText = s;
                 cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar).Value = makhoahoc;
                 cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                 SqlDataAdapter da = new SqlDataAdapter();
                 da.SelectCommand = cmd;
                 DataTable dt = new DataTable();
                 da.Fill(dt);

                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
                     DTO_QLPhanCongDT PCDT = new DTO_QLPhanCongDT();
                     PCDT.ID_PCDT = int.Parse(dt.Rows[i]["ID_PCDT"].ToString());
                     PCDT.MaDT = dt.Rows[i]["MaDT"].ToString();
                     PCDT.MaSV = dt.Rows[i]["MaSV"].ToString();
                     PCDT.MaCN = dt.Rows[i]["MaCN"].ToString();
                     PCDT.MaKH = dt.Rows[i]["MaKH"].ToString();
                     PCDT.MaLoaiDT = dt.Rows[i]["MaLoaiDT"].ToString();
                     PCDT.NgayNhan = DateTime.Parse(dt.Rows[i]["NgayNhan"].ToString());
                     PCDT.NgayHetHan_ChonDT = DateTime.Parse(dt.Rows[i]["NgayHetHan_ChonDT"].ToString());
                     PCDT.Nhom = int.Parse(dt.Rows[i]["Nhom"].ToString());
                     PCDT.DiemNHD = float.Parse(dt.Rows[i]["DiemNHD"].ToString());
                     PCDT.DiemPB = float.Parse(dt.Rows[i]["DiemPB"].ToString());
                     listPCDT.Add(PCDT);
                 }
                 ketnoi.Cmb().Close();
                 return listPCDT;
             }
             catch (Exception ex)
             {
                 return listPCDT;
             }
         }*/
        public static bool KiemTraDKLoaiUpdateDT01(string MaSV, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "proc_KiemTraDKLoaiDT01";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaSV", SqlDbType.NVarChar).Value = MaSV;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                    return true;
                ketnoi.Cmb().Close();
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public static bool KiemTraDKLoaiInsertDT01(string MaSV, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "proc_KiemTraDKLoaiInsertDT01";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaSV", SqlDbType.NVarChar).Value = MaSV;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                    return true;
                ketnoi.Cmb().Close();
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        //////////////huyen lam de tai 03//////////////////////////////////
        public static bool KiemTraDKLoaiUpdateDT03(string MaSV, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "proc_KiemTraDKLoaiDT03";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaSV", SqlDbType.NVarChar).Value = MaSV;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                    return true;
                ketnoi.Cmb().Close();
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public static bool KtratontaiLoaiDT03(string MaSV, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "Prc_KtratontaiLoaiDT03";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaSV", SqlDbType.NVarChar).Value = MaSV;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
               // cmd.Parameters.Add("@MaDT", SqlDbType.NVarChar).Value = madt;
           
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                    return true;
                ketnoi.Cmb().Close();
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public static bool KiemTraDKLoaiInsertDT03(string MaSV, string maloaidt)
        {
            List<DTO_QLPhanCongDT> listPCDT = new List<DTO_QLPhanCongDT>();
            try
            {
                string s = "proc_KiemTraDKLoaiInsertDT03";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaSV", SqlDbType.NVarChar).Value = MaSV;
                cmd.Parameters.Add("@MaLoaiDT", SqlDbType.NVarChar).Value = maloaidt;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count > 0)
                    return true;
                ketnoi.Cmb().Close();
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
